package com.leetcode.algorithm.y22.m07;

import com.leetcode.algorithm.common.TreeNode;

/**
 * 404. 左叶子之和
 * 
 * https://leetcode.cn/problems/sum-of-left-leaves/
 * 
 * @author jie.deng
 *
 */
class Question0404Solution01 {
	
	public int sumOfLeftLeaves(TreeNode root) {
		if (root == null) {
			return 0;
		}
		int sum = 0;
		if (root.left != null) {
			TreeNode cur = root.left;
			if (cur.left == null && cur.right == null) {
				// 左叶子
				sum += cur.val;
			} else {
				sum += sumOfLeftLeaves(root.left);
			}
		}
		sum += sumOfLeftLeaves(root.right);
		return sum;
	}
    
}